from datetime import date,datetime
import numbers
class IntFileld(object):
    def __get__(self, instance, owner):
        return self.value
    def __set__(self, instance, value):
        if not isinstance(value,numbers.Integral):
            raise ValueError('int value need')
        if value<0:
            raise ValueError('positive value need')
        self.value=value
    def __delete__(self, instance):
        pass

class NonDataIntField:
    #非数据属性描述符
    def __get__(self, instance, owner):
        return self.value
class Module:
    age=IntFileld()

class User:
    def __init__(self,name,birthday):
        self.name=name
        self.birthday=birthday
        self._age=0

    def get_age(self):
        return datetime.now().year-self.birthday.year

    @property
    def age(self):
        return datetime.now().year-self.birthday.year

    @age.setter
    def age(self,value):
        self._age=value#不想让这个属性在代码中显示出来,user._age不会有提示

if __name__ == '__main__':
    user=User('AK',date(year=2001,month=4,day=29))
    res=user.get_age()
    print(res)
    print(user.age)
    user.age=18
    print(user._age)
    module=Module()
    module.age=30
    print(module.age)


